<?php

/**
 * Custom view resource, which overides the default one.
 * This adds the additional option to specify helper paths in the application config
 */
class Resource_View extends Zend_Application_Resource_ResourceAbstract
{
    public function init() 
    {
        $options = $this->getOptions();
        
        // Create the view as normally, passing the options foward
        $view = new Zend_View($options);
        
        
        // Setup any view helpers defined in the config
        if (isset($options['helperPaths'])) {
            foreach ($options['helperPaths'] as $classPrefix => $path) {
                $view->addHelperPath($path, $classPrefix);
            }
        }
        
        if (isset($options['scriptPaths'])) {
            foreach ($options['scriptPaths'] as $path) {
                $view->addScriptPath($path);
            }
        }
        
        // Some other stuff, this is as good a place as any to put it i guess
        $view->doctype('XHTML1_STRICT');
        //$view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');
    
        // Assign the view to the view renderer
        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
        $viewRenderer->setView($view);
        
        /*
        // Setup jquery
        $jquery = $view->jQuery();
        $jquery->setLocalPath('js/jquery/jquery-1.3.2.min.js')
               ->uiEnable()
               ->enable();
        */
        // The last thing returned from a resource will be stored in the resource registry 
        // under the name of the resource. This means that we will put the created view into
        // the registry under the name "view"
        return $view;
    }
}
